﻿using AutoMapper;
using DTOModels.Menu;
using DTOModels.Role;
using DTOModels.User;
using Models.Entity;

namespace BusinessInterface.Map
{
    /// <summary>
    /// AutoMapper映射关系配置
    /// </summary>
    public class AutoMapperConfigs : Profile
    {
        /// <summary>
        /// 配置映射
        /// </summary>
        public AutoMapperConfigs()
        {
            CreateMap<PagingData<Sys_User>, PagingData<SysUserDto>>();
            CreateMap<Sys_User, SysUserInfo>();
            CreateMap<Sys_User, SysUserDto>().ReverseMap();
            CreateMap<Sys_Menu, SysRouteTreeDTO>().ReverseMap();
            CreateMap<PagingData<Sys_Menu>, PagingData<SysMenuDTO>>();
            CreateMap<Sys_Menu, SysMenuDTO>()
                .ForMember(
                    s => s.ParentId,
                    m => m.MapFrom(x => x.ParentId == null ? default : x.ParentId)
                )
                .ReverseMap();


            CreateMap<Sys_Role, SysRoleDTO>().ReverseMap();
            CreateMap<PagingData<Sys_Role>, PagingData<SysRoleDTO>>().ReverseMap();
        }
    }
}
